Ext.define('pm.view.Personal.List' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.PersonalList',

    store: 'Personal',

    viewConfig: {
        plugins: [
            {
                ddGroup: 'GridExample2',
                ptype: 'gridviewdragdrop',
            },
        ]
    },
    columns: [
        {header: 'Name',  dataIndex: 'name',  flex: 1},
        {header: 'Email', dataIndex: 'email', flex: 1}
    ],

    listeners: {
        render: function(v) {
            this.getView().on('beforedrop', function(node, data, dropRec, dropPosition) {
                if(data.records.length) {
                    return v.dragItemToTarget(data.records[0], dropRec)
                }
                return false
            })
        }
    },

    dragItemToTarget: function(item, target) {
        console.log('drag ' + item.get('name') + ' on ' + target.get('name') + ', dropped class=' + item.self.getName())

        if(item.self.getName() == 'pm.model.Personal') {
            return true
        } else if(item.self.getName() == 'pm.model.Project') {
            this.fireEvent('addProjectToUser', item, target)
            return false
        }
    },

    initComponent: function() {

        this.callParent(arguments);

    }
});